package project2;

public class Cell implements Comparable<Cell> {


    /*********************************************************************
     * Cell represents a cell in the matrix used to find an optimal MSA
     * coord: the coordinates of the cell
     * k: the number of coordinates
     * val: the value asigned to the cell
     *********************************************************************/

    private int[] coord;
    private int k;
    private int val;


    /*********************************************************************
     *constructor using an array
     *********************************************************************/

    public Cell(int v, int dim, int[] c) {
        this.val = v;
        this.k = dim;
        for(int i=0; i<k; i++)
            this.coord[i] = c[i];
    }


    /*********************************************************************
     * constructor using a single value that will be assigned to all coordinates
     *********************************************************************/

    public Cell(int v, int dim, int c) {
        this.val = v;
        this.k = dim;
        this.coord = new int[this.k];
        for(int i=0; i<k; i++)
            this.coord[i] = c;
    }


    /*********************************************************************
     * copy constructor
     *********************************************************************/

    public Cell(Cell c) {
        this.val = c.val;
        this.k = c.k;
        this.coord = new int[this.k];
        for(int i=0; i<k; i++)
            this.coord[i] = c.coord[i];
    }


    /*********************************************************************
     * constructor using a variable number of parameters
     *********************************************************************/

    public Cell(int v, int... values) {
        val = v;
        k = values.length;
        coord = values;
    }


    /*********************************************************************
     * returns true iif this cell is equal with cell o
     *********************************************************************/

    /*public boolean equals(Object o) {
        if (!(o instanceof Cell))
            return false;
        Cell c = (Cell) o;
        if(c.k==this.k) {
            for(int i=0; i<this.k; i++)
                if(c.coord[i]!=this.coord[i])
                    return false;
        }
        else
            return false;
        return true;
    }*/


    /*********************************************************************
     * returns:
     * -1 if the this cell is before cell c in lexicographic order
     * 0 if they're equal
     * 1 otherwise
     *********************************************************************/

    public int compareTo(Cell c) {
        if(this.k < c.k)
            return -1;
        if(this.k > c.k)
            return 1;
        for(int i=0; i<this.k; i++)
            if(this.coord[i]<c.coord[i])
                return -1;
            else
                if(c.coord[i]<this.coord[i])
                    return 1;
        return 0;
    }

    public void modify_value(int v){
        this.val = v;
    }

    public int get_value(){
        return this.val;
    }

    public int get_coord_at(int i){
        return this.coord[i];
    }

    public int[] get_coord(){
        return this.coord;
    }

    public void modify_coord_at(int i, int j) {
        this.coord[i] += j;
    }

    public void print(){
        System.out.print(val+" : ");
        for(int i=0; i<k; i++)
            System.out.print(coord[i]+" ");
        System.out.println();
    }



}
